
#ifndef CARPLAY_PROTOCOL_H
#define CARPLAY_PROTOCOL_H

#ifdef  __cplusplus
extern "C" {
#endif

#include <stdio.h>
#include <stdint.h>

typedef enum
{
	DongleUsbHost = 0,
	DongleUsbDevice
} DongleUsbMode;

typedef enum
{
    DongleAudioStreamMedia = 0, // 音乐
    DongleAudioStreamCall,		// 电话
    DongleAudioStreamRECOGNITION, // siri
    DongleAudioStreamAlt,      // 辅助音,包括导航音,系统提示音
    DongleAudioStreamRec,		 // 录音
    DongleAudioStreamAlert
} DongleAudioStreamType;

typedef int		DongleCarplayEntity;

typedef int		DongleCarplaySpeechMode;

typedef struct
{
	DongleCarplayEntity			entity;
	DongleCarplaySpeechMode		mode;

}	DongleCarPlaySpeechState;

typedef struct
{
	DongleCarplayEntity			screen;		// Owner of the screen.
	DongleCarplayEntity			mainAudio;	// Owner of main audio.
	DongleCarplayEntity			phoneCall;	// Owner of phone call.
	DongleCarPlaySpeechState	speech;		// Owner of speech and its mode.
    DongleCarplayEntity			turnByTurn;	// Owner of navigation.

} DongleCarPlayModeState;

//typedef struct
//{
//    CarplayEntity			screen;		// Owner of the screen.
//    CarplayEntity			mainAudio;	// Owner of main audio.
//    CarplayEntity			phoneCall;	// Owner of phone call.
//    CarPlaySpeechState		speech;		// Owner of speech and its mode.
//    CarplayEntity			turnByTurn;	// Owner of navigation.
//
//} CarPlayModeState;


typedef void (*ProtocolIAP2LinkStatus)(int /*status*/);
typedef int (*ProtocolIAP2WriteData)(char * /*buf*/,int /*len*/);
typedef void (*ProtocolCarPlaySessionStart)();
typedef void (*ProtocolCarPlaySessionStop)();
typedef int (*ProtocolSwitchUsbModeCB)(DongleUsbMode /*mode*/);
typedef void (*ProtocolAppleTimeUpdateCB)(long long /*time*/);
typedef void (*ProtocolAppleLanguageUpdateCB)(const char */*lang*/);
typedef void (*ProtocolAppleCallStateUpdateCB)(const char */*remoteId*/, const char */*displayName*/,
		int /*status*/, int /*direction*/, const char */*uuid*/, const char */*addrBookId*/,
		const char */*label*/, int /*service*/);

typedef void (*ProtocolAppleNowPlayingUpdateCB)(const char */*mediaItemTitle*/, const char */*mediaItemAlbumTitle*/,
		 const char */*mediaItemArtist*/,int /*mediaDuration*/,int /*state*/);

typedef void (*ProtocolNotifyDeviceNameCB)(const char */*name*/, int /*name_len*/);
typedef void (*ProtocolCarPlayExitCB)();
typedef void (*ProtocolReturnNativeUICB)();
typedef void (*ProtocolModesChangeCB)(DongleCarPlayModeState */*modes*/);
typedef void (*ProtocolDisableBluetoothCB)();
typedef void (*ProtocolCarPlayDuckAudioCB)(double /*inDurationSecs*/, double /*inVolume*/);
typedef void (*ProtocolCarPlayUnduckAudioCB)(double /*inDurationSecs*/);
typedef void (*ProtocolCarPlayAudioStartCB)(int /*handle*/, DongleAudioStreamType/* type*/, int/* rate*/, int /*bits*/,
		int /*channels*/);
typedef void (*ProtocolCarPlayAudioStopCB)(int /*handle*/, DongleAudioStreamType /*type*/);
typedef int (*ProtocolCarPlayVideoStartCB)();
typedef void (*ProtocolCarPlayVideoStopCB)();
typedef int (*ProtocolCarPlayVideoDataProcCB)(const char */*buf*/, int /*len*/);


typedef struct
{
	ProtocolIAP2LinkStatus              protocolIAP2LinkStatus_f;
	ProtocolIAP2WriteData               protocolIAP2WriteData_f;
	ProtocolCarPlaySessionStart         protocolCarPlaySessionStart_f;
	ProtocolCarPlaySessionStop          protocolCarPlaySessionStop_f;
	ProtocolSwitchUsbModeCB             protocolSwitchUsbModeCB_f;
	ProtocolAppleTimeUpdateCB           protocolAppleTimeUpdateCB_f;
	ProtocolAppleLanguageUpdateCB       protocolAppleLanguageUpdateCB_f;
	ProtocolAppleCallStateUpdateCB      protocolAppleCallStateUpdateCB_f;
	ProtocolAppleNowPlayingUpdateCB     protocolAppleNowPlayingUpdateCB;
	ProtocolNotifyDeviceNameCB          protocolNotifyDeviceNameCB_f;
	ProtocolCarPlayExitCB               protocolCarPlayExitCB_f;
	ProtocolReturnNativeUICB            protocolReturnNativeUICB_f;
	ProtocolModesChangeCB               protocolModesChangeCB_f;
	ProtocolDisableBluetoothCB          protocolDisableBluetoothCB_f;
	ProtocolCarPlayDuckAudioCB          protocolCarPlayDuckAudioCB_f;
	ProtocolCarPlayUnduckAudioCB        protocolCarPlayUnduckAudioCB_f;
	ProtocolCarPlayAudioStartCB         protocolCarPlayAudioStartCB_f;
	ProtocolCarPlayAudioStopCB          protocolCarPlayAudioStopCB_f;
	ProtocolCarPlayVideoStartCB         protocolCarPlayVideoStartCB_f;
	ProtocolCarPlayVideoStopCB          protocolCarPlayVideoStopCB_f;
	ProtocolCarPlayVideoDataProcCB      protocolCarPlayVideoDataProcCB_f;

} CarPlayProtocolDelegate;

#define CarPlayProtocolDelegateInit( PTR )	memset( (PTR), 0, sizeof( CarPlayProtocolDelegate ) );

void CarPlayProtocolSetDelegate( const CarPlayProtocolDelegate *inDelegate );


// the following is call by protocol stack
void iap2LinkStatus(int status);

int iap2WriteData(char *buf, int len);

void carplaySessionStart();

void carplaySessionStop();

int switchUsbModeCB(DongleUsbMode mode);

void appleTimeUpdateCB(long long time);

void appleLanguageUpdateCB(const char *lang);

void appleCallStateUpdateCB(const char *remoteId,
										const char *displayName,
										int status,
										int direction,
										const char *uuid,
										const char *addrBookId,
										const char *label,
										int service);

void appleNowPlayingUpdateCB(const char *mediaItemTitle,
										const char *mediaItemAlbumTitle,
										const char *mediaItemArtist,
										int mediaDuration,int state);

void NotifyDeviceNameCB(const char *name, int name_len);

   /* *
    * @brief 退出的通知
    * */
void carplayExitCB();
   /* *
    * @brief 点击返回本地界面的按钮通知
    * */
void returnNativeUICB();
   /* *
    * @brief carplay模式改变的通知
    * */
void modesChangeCB(DongleCarPlayModeState *modes);
   /* *
    * @brief carplay禁止蓝牙
    * */
void disableBluetoothCB();

	/* *
    * @brief 压低其他音频流音量
    * */
void caplayDuckAudioCB(double inDurationSecs, double inVolume);
   /* *
    * @brief 还原其他音频流音量
    * */
void caplayUnduckAudioCB(double inDurationSecs);

	 /* *
    * @brief 音频流开始
    * @param 			handle 		该路音频流的操作句柄,要缓存起来,作为playStream/recordStream的第一个参数
    * @param			type  		音频流类型
    * @param 			rate		音频的采样率
    * @param 			bits		音频位宽
    * @param 			channels	音频通道数
    * */
void carplayAudioStartCB(int handle, DongleAudioStreamType type, int rate, int bits, int channels);
   /* *
    * @brief 音频流停止
    * */
void carplayAudioStopCB(int handle, DongleAudioStreamType type);

   /* *
    * @brief 视频流开始
    * */
int carplayVideoStartCB();
   /* *
    * @brief 视频流停止
    * */
void carplayVideoStopCB();
    /* *
    * @brief 视频流数据处理
    * */
int carplayVideoDataProcCB(const char *buf, int len);

#ifdef  __cplusplus
}  
#endif
#endif //CARPLAY_PROTOCOL_H
